import { Form } from 'antd';
import { axconst } from '@/shared/axconst';
import { AxValidator } from '../AxValidator';
import ReactUeditor from 'react-ueditor';

const FormItem = Form.Item;
const {
  inlineFormItemLayout,
  inlineFormItemLayoutAllRowTwo,
  inlineFormItemLayoutAllRowThree,
} = axconst;
/**
 * 自定义CheckboxGroup
 * @param label 标签
 * @param field 字段名称
 * @param value 值
 * @param placeholder 占位符
 * @param hidden 是否隐藏
 */
export function AxUeditor(props) {
  const {
    formItemLayoutFromProps = null,
    wholerow,
    hidden,
    label,
    form,
    field,
    value,
    placeholder,
    required,
    validator,
    formItemStyle = null,
    handleReadUeditorValue,
    ...rest
  } = props;
  let formItemLayout = {};
  switch (wholerow) {
    case 'two':
      formItemLayout = { ...inlineFormItemLayoutAllRowTwo };
      break;
    case 'three':
      formItemLayout = { ...inlineFormItemLayoutAllRowThree };
      break;
    default:
      formItemLayout = formItemLayoutFromProps
        ? formItemLayoutFromProps
        : { ...inlineFormItemLayout };
      break;
  }

  const uploadImage = e => {
    return new Promise(function(resolve, reject) {
      let file = e.target.files[0];

      // 在这里将你的图片上传到服务器，在上传成功的回调中执行
      resolve(imgUrl);
    });
  };

  return hidden ? null : (
    <FormItem {...formItemLayout} label={label} style={formItemStyle}>
      {/* {form.getFieldDecorator(field, {
                initialValue: value,
                rules: [
                    {
                        label: props.label,
                        required: props.required,
                        validator: validator ? validator : AxValidator,
                    },
                ],
            })( */}
      <ReactUeditor
        config={{ enableAutoSave: false }}
        onChange={handleReadUeditorValue}
        // plugins={['uploadImage', 'insertCode']}
        // uploadImage={uploadImage}
        // ueditorPath="/js/ueditor"
        value={value}
        {...rest}
      />
      {/* )} */}
    </FormItem>
  );
}
